#include "dialog.h"
#include <QLabel>
#include <QLineEdit>
#include <QComboBox>
#include <QPushButton>
#include <QFrame>
#include <QGridLayout>
#include <QPixmap>
#include <QHBoxLayout>

Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
{
    setWhatsThis(tr("UserInfo"));
    /*------------------左侧--------------------------*/
       /*---初始化控件*/
    UserNameLabel = new QLabel(tr("用户名："));
    UserNameLineEdit = new QLineEdit;
    NameLabel = new QLabel(tr("姓名："));
    NameLineEdit =new QLineEdit;
    SexLabel = new QLabel(tr("性别："));
    SexComboBox = new QComboBox;
    SexComboBox ->addItem(tr("女"));
    SexComboBox ->addItem(tr("男"));
    SexComboBox ->addItem(tr("不详"));
    DepartmentLabel = new QLabel(tr("部门："));
    DepartmentTextEdit = new QTextEdit;
    AgeLabel = new QLabel(tr("年龄："));
    AgeLineEdit = new QLineEdit;
    OtherLabel = new QLabel(tr("备注："));
    OtherLabel -> setFrameStyle(QFrame::Panel|QFrame::Sunken);//控件风格，形状和阴影
       /*----布局控件----*/
    LeftLayout = new QGridLayout();  //不是主布局，不用指定父窗口
    LeftLayout->addWidget(UserNameLabel,0,0);
    LeftLayout->addWidget(UserNameLineEdit,0,1);
    LeftLayout->addWidget(NameLabel,1,0);        //姓名
    LeftLayout->addWidget(NameLineEdit,1,1);
    LeftLayout->addWidget(SexLabel,2,0);  //性别
    LeftLayout->addWidget(SexComboBox,2,1);
    LeftLayout->addWidget(DepartmentLabel,3,0);//部门
    LeftLayout->addWidget(DepartmentTextEdit,3,1);
    LeftLayout->addWidget(AgeLabel,4,0); //年龄
    LeftLayout->addWidget(AgeLineEdit,4,1);
    LeftLayout->addWidget(OtherLabel,5,0,1,2);//其他
    LeftLayout->setColumnStretch(0,1);
    LeftLayout->setColumnStretch(1,3);  //设定两列分别占用的空间比列，此处设定为1：3

    /*---------------右侧-----------------*/
      /*初始化控件*/
    HeadLabel =new QLabel(tr("头像："));//右上角部分
    HeadIconLabel = new QLabel;
    QPixmap icon("111.png");
    HeadIconLabel->setPixmap(icon);
    HeadIconLabel->resize(icon.width(),icon.height());
    UpdateHeadBtn = new QPushButton(tr("更新"));
    //布局--右上侧
    TopRightLayout = new QHBoxLayout();
    TopRightLayout->setSpacing(20);  //设定间距
    TopRightLayout->addWidget(HeadLabel);
    TopRightLayout->addWidget(HeadIconLabel);
    IntroductionLabel=new QLabel(tr("个人说明"));  //右下角
    IntroductionTextEdit=new QTextEdit;
    //布局右侧
    RightLayout = new QVBoxLayout();
    RightLayout->addLayout(TopRightLayout);
    RightLayout->addWidget(IntroductionLabel);
    RightLayout->addWidget(IntroductionTextEdit);

    /*---------------底部-----------------------*/
    OkBtn = new QPushButton(tr("确定"));
    CancelBtn = new QPushButton(tr("取消"));
    //下方按钮
    ButtomLayout = new QHBoxLayout();
    ButtomLayout -> addStretch();  //锁定按钮大小，使按钮紧靠
    ButtomLayout -> addWidget(OkBtn);
    ButtomLayout -> addWidget(CancelBtn);

    QGridLayout * mainLayout = new QGridLayout(this);   //实现主布局。
    mainLayout -> setMargin(15);
    mainLayout -> setSpacing(10);
    mainLayout -> addLayout(LeftLayout,0,0);
    mainLayout -> addLayout(RightLayout,0,1);
    mainLayout -> addLayout(ButtomLayout,1,0,1,2);
    mainLayout -> setSizeConstraint(QLayout::SetFixedSize); //设定最优显示，用户不可改变对话框的大小。

}


Dialog::~Dialog()
{

}
